/* Copyright 2011 Rok Lenarčič 
 * 
 * This file is a part of MicroFn.
 * 
 * MicroFn is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * MicroFn is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/> */

package net.rlenar.microfn;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
/**
 * 
 * @author rok.lenarcic
 *
 */
public abstract class CollectionFactory {
	public static CollectionFactory activeCollectionFactory = new BasicCollectionFactory();
	public abstract <T> List<T> getListInstance();
	public abstract <T> List<T> getListInstance(int size);	
	public abstract <T> Set<T> getSetInstance();
	public abstract <T> Set<T> getSetInstance(int size);
	public abstract <T> SortedSet<T> getSortedSetInstance();
	public abstract <K,V> SortedMap<K,V> getSortedMapInstance();
	public abstract <T> SortedSet<T> getSortedSetInstance(Comparator<? super T> comp);
	public abstract <K,V> SortedMap<K,V> getSortedMapInstance(Comparator<? super K> comp);	
	public abstract <K,V> Map<K,V> getMapInstance();
	public abstract <K,V> Map<K,V> getMapInstance(int size);
	public static class BasicCollectionFactory extends CollectionFactory {

		@Override
		public <T> List<T> getListInstance() {
			return new ArrayList<T>();
		}

		@Override
		public <T> Set<T> getSetInstance() {
			return new HashSet<T>();
		}

		@Override
		public <K,V> Map<K,V> getMapInstance() {
			return new HashMap<K,V>();
		}

		@Override
		public <T> SortedSet<T> getSortedSetInstance() {
			return new TreeSet<T>();
		}

		@Override
		public <K,V> SortedMap<K,V> getSortedMapInstance() {
			return new TreeMap<K,V>();
		}

		@Override
		public <T> List<T> getListInstance(int size) {
			return new ArrayList<T>(size);
		}

		@Override
		public <T> Set<T> getSetInstance(int size) {
			return new HashSet<T>(size);
		}

		@Override
		public <K, V> Map<K, V> getMapInstance(int size) {
			return new HashMap<K,V>(size);
		}

		@Override
		public <T> SortedSet<T> getSortedSetInstance(Comparator<? super T> comp) {
			return new TreeSet<T>(comp);
		}

		@Override
		public <K, V> SortedMap<K, V> getSortedMapInstance(
				Comparator<? super K> comp) {
			return new TreeMap<K, V>(comp);
		}
		
	}
}
